package com.talent.datasource.influxdb;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
//@ConditionalOnMissingBean({TalentInfluxDBService.class})
@EnableConfigurationProperties({TalentInfluxDBProperties.class})
public class TalentInfluxdbConfig {


    @Autowired
    TalentInfluxDBProperties properties;
    @Bean
    public TalentInfluxDBService influxDBService(){

        if(properties.getUrl()==null){
            throw new IllegalArgumentException("influxdb url is null");
        }
        if(properties.getToken()==null){
            throw new IllegalArgumentException("influxdb token is null");
        }
        if(properties.getOrg()==null){
            throw new IllegalArgumentException("influxdb org is null");
        }
        if(properties.getBucket()==null){
            throw new IllegalArgumentException("influxdb bucket is null");
        }
        return new TalentInfluxDBService(properties);
    }



}
